package cn.softcits.thread.even2;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-04 8:59 PM
 */
public class PrintNumber {

    private Integer number = 0;

    public synchronized void printEven() {
        if (number % 2 == 0) {
            System.out.println(Thread.currentThread().getName() + " is printing Even: " + number);
            number++;
            this.notify();
        } else {
            try {
                Thread.sleep(1000);
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void printOdd() {
        if (number % 2 != 0) {
            System.out.println(Thread.currentThread().getName() + " is printing Odd: " + number);
            number++;
            this.notify();
        } else {
            try {
                Thread.sleep(1000);
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


}
